package com.clouree.anelib
{
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	import flash.events.StatusEvent;
	import flash.external.ExtensionContext;
	
	public class AneEventsDispatcher extends EventDispatcher
	{
		private static var extContext:ExtensionContext = null;
		private static const ANE_ALERT:String ="showDialog";
		private static const ANE_NOTIFY_type:String = "notifyType";
		private static const ANE_NOTIFY_CONTENT:String = "notifyContent";
		private static const ANE_SEND_MESSAGE:String = "sendMessage";
		private static const ANE_CALL_PHONE:String = "callPhone";
		
		public function AneEventsDispatcher(target:IEventDispatcher=null)
		{

			super(target);
						trace("init AneEventsDispatcher");
			initExtensionContext();
			addEvent();
			
		}
		
		private function initExtensionContext():void
		{
			trace("begin create extContext");
			if(extContext == null)
			{
				extContext = ExtensionContext.createExtensionContext("com.mobile.cloureeAne","");
				trace("create success");
			}
		}
		
		private function addEvent():void
		{
			if(extContext)
			{
				extContext.addEventListener(StatusEvent.STATUS,statusEventHandler);
			}
		}
		
//		ane call air to do sth
		protected function statusEventHandler(event:StatusEvent):void
		{
			// TODO Auto-generated method stub
			trace("ane call air to do sth ------ANE(AS) + code:" + event.code);
		}
		/**
		 *调用弹窗（单按钮） 
		 * @param showStr 提示文字
		 * @param buttonStr 按钮上显示的文字
		 * @param title 标题显示文字
		 * 
		 */
		public function showDialog(showStr:String = "hello java world",buttonStr:String = "确定",title:String = "提示"):void
		{
			trace("showDialog --dddd----ANE(AS)ddd");
			extContext.call(ANE_ALERT,showStr,buttonStr,title);
		}
		/**
		 *设置顶部通知的方式 震动或者声音加震动 
		 * @param isWake
		 * 
		 */		
		public function setMessageNotifyType(isWake:Boolean):void
		{
			extContext.call(ANE_NOTIFY_type,isWake);
		}
		/**
		 *发送顶部通知 
		 * @param content 通知内容
		 * @param title 通知标题
		 * 
		 */		
		public function setMessageNotifyContent(content:String,title:String):void
		{
			extContext.call(ANE_NOTIFY_CONTENT,content,title);
		}
		/**
		 *发送短信 
		 * @param content 短信内容
		 * 
		 */		
		public function sendMessage(content:String,number:String = "13287870801"):void
		{
			extContext.call(ANE_SEND_MESSAGE,content,number);
		}
		
		/**
		 *打电话 
		 * @param number
		 * 
		 */		
		public function callPhone(number:String):void
		{
			extContext.call(ANE_CALL_PHONE,number);
		}
		
	}
}